package br.jcrsistemas.componentes;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

public class SysCampoValor extends JNumberFormatField{
	
	private Component nextComponente;
	private boolean obrigatorio;
	public SysCampoValor() {
		super();
		setObrigatorio(false);
		addFocusListener( new ActionFoco() );
		setLimit(15);
	}
	
	public void setNextComponente( Component nextComponente ) {
		this.nextComponente = nextComponente;
	}

	public Component getNextComponente( ) {
		return nextComponente;
	}

	public void setObrigatorio( boolean obrigatorio ) {
		this.obrigatorio = obrigatorio;
	}

	public boolean isObrigatorio( ) {
		return obrigatorio;
	}

	public class ActionFoco implements FocusListener {

		@Override
		public void focusGained(FocusEvent arg0) {
			SysCampoValor componente = (SysCampoValor) arg0.getComponent();
			componente.setBackground( new Color(Integer.parseInt("FFE87C", 16)) );
			
		}

		@Override
		public void focusLost(FocusEvent arg0) {
			SysCampoValor componente = (SysCampoValor) arg0.getComponent();
			
			componente.setBackground(Color.WHITE);
			if(getNextComponente() != null) {
					getNextComponente().requestFocus();
			}
			
		}
		
	}
	

}
